<?php

namespace app\common\model;

use think\Db;

/**
 *  单页分类表
 */
class Singles extends Base {

    /**
     * 获取列表
     */
    public function getAll() {
        return (Object) $this->order('id', 'desc')->select()->toArray();
    }

    public function getListAll($type) {

        $page = input('get.page');
        $limit = input('get.limit');
        $where = '1=1';

        if (input('get.key/a')) {
            foreach (input('get.key/a') as $k => $v) {
                if (!empty($v)) {
                    switch ($k) {
                        case "title":
                            $where.=" and {$k} like '%{$v}%'";
                            break;
                        case "author":
                            $where.=" and {$k} like '%{$v}%'";
                            break;
                    }
                }
            }
        }
        if ($type == 1) {//分页
            return $this->where($where)->page($page, $limit)->select()->toArray();
        } else {//总数
            return $this->where($where)->select()->toArray();
        }
    }

}
